package logic

import (
	"context"
	"errors"
	"fmt"
	"week/model/mysql"

	"week/user-srv/internal/svc"
	"week/user-srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type SaveRealAuthLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSaveRealAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveRealAuthLogic {
	return &SaveRealAuthLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SaveRealAuthLogic) SaveRealAuth(in *user.SaveRealAuthRequest) (*user.SaveRealAuthResponse, error) {
	// todo: add your logic here and delete this line
	r := mysql.RealAuth{
		UserId:   int(in.UserId),
		IdCard:   in.IdCard,
		RealName: in.RealName,
	}

	fmt.Println(r)
	err := r.CreateRealAuth()
	if err != nil {
		return nil, errors.New("实名信息保存失败")
	}
	return &user.SaveRealAuthResponse{Success: true}, nil
}
